﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using System.Data;
using Maticsoft.DBUtility;
namespace BLL
{
    public class AdminConfigBLL
    {
        /// <summary>
        /// 管理员登陆
        /// </summary>
        /// <returns></returns>
        public static DataSet AdminLogin(string username,string password)
        {
            string sqlstr = "select * from b_admin where adminname = '" + username + "' and adminpassword = '" + password + "'";
            DataSet ds = DbHelperOra.Query(sqlstr);
            
            return  ds;
            
        }

        public static DataSet GetAdminByID(int id)
        {
            string sql = "select * from b_admin where id = "+id.ToString();
            return DbHelperOra.Query(sql);
        }

        public static DataSet GetAllAdmin()
        {
            string sql = "select * from v_admin ";
            return DbHelperOra.Query(sql);
        }

        public static DataSet GetAllAdminByAdminName(string name)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select * from v_admin ");
            if (!name.Equals(""))
            {
                sb.Append("where adminname like '%");
                sb.Append(name);
                sb.Append("%'");
            }
            return DbHelperOra.Query(sb.ToString());
        }

        public static int DelAdminByID(int id)
        {
            string sqlstr = "delete from b_admin where id = " + id.ToString();
            return DbHelperOra.ExecuteSql(sqlstr);
        }

        public static int UpdateAdmin(int id,string adminname,string adminpassword,string adminlevel)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("update b_admin set ");
            sb.Append("adminname = :v_adminname,");
            sb.Append("adminpassword = :v_adminpassword,");
            sb.Append("adminlevel = :v_adminlevel ");
            sb.Append(" where id = :v_id");

            OracleParameter[] para = {
                                          new OracleParameter(":v_adminname",OracleType.VarChar),
                                          new OracleParameter(":v_adminpassword",OracleType.VarChar),
                                          new OracleParameter(":v_adminlevel",OracleType.VarChar),
                                          new OracleParameter(":v_id",OracleType.Number)
                                      };
            para[0].Value = adminname;
            para[1].Value = adminpassword;
            para[2].Value = adminlevel;
            para[3].Value = id;
            return DbHelperOra.ExecuteSql(sb.ToString(), para);
        }

        public static int AddAdmin(string adminname, string adminpassword, string adminlevel)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into b_admin(");
            strSql.Append("adminname,adminpassword,adminlevel)");
            strSql.Append(" values (");
            strSql.Append(":v_adminname,:v_adminpassword,:v_adminlevel)");
            OracleParameter[] parameters = {
					
					new OracleParameter(":v_adminname", OracleType.VarChar),
					new OracleParameter(":v_adminpassword", OracleType.VarChar),
					new OracleParameter(":v_adminlevel", OracleType.VarChar),
					};
            parameters[0].Value = adminname;
            parameters[1].Value = adminpassword;
            parameters[2].Value = adminlevel;

            return DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
        }


        //以下是对b_userlevel表进行操作
        public static DataSet GetUserLevelByID(int id)
        {
            string sqlstr = "select id,userlevelname,piccount,basemark from b_userlevel where id = "+id.ToString();
            return DbHelperOra.Query(sqlstr);

        }

        public static DataSet FindUserLevelByName(string strwhere)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select id,userlevelname,piccount,basemark from b_userlevel ");
            if(!strwhere.Equals(""))
            {
                sb.Append("where userlevelname like '%");
                sb.Append(strwhere);
                sb.Append("%'");
            }

            return DbHelperOra.Query(sb.ToString());
        }

        public static int UpdateUserLevel(int id, string userlevelname, int piccount, int basemark)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("update b_userlevel set ");
            sb.Append("userlevelname = :v_userlevelname,");
            sb.Append("piccount = :v_piccount,");
            sb.Append("basemark = :v_basemark ");
            sb.Append(" where id = :v_id");

            OracleParameter[] para = {
                                          new OracleParameter(":v_userlevelname",OracleType.VarChar),
                                          new OracleParameter(":v_piccount",OracleType.Number),
                                          new OracleParameter(":v_basemark",OracleType.Number),
                                          new OracleParameter(":v_id",OracleType.Number)
                                      };
            para[0].Value = userlevelname;
            para[1].Value = piccount;
            para[2].Value = basemark;
            para[3].Value = id;
            return DbHelperOra.ExecuteSql(sb.ToString(), para);
        }

        public static int AddUserLevel(string userlevelname, int piccount, int basemark)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into b_userlevel(");
            strSql.Append("userlevelname,piccount,basemark)");
            strSql.Append(" values (");
            strSql.Append(":v_userlevelname,:v_piccount,:v_basemark)");
            OracleParameter[] parameters = {
					
					new OracleParameter(":v_userlevelname", OracleType.VarChar),
					new OracleParameter(":v_piccount", OracleType.Number),
					new OracleParameter(":v_basemark", OracleType.Number),
					};
            parameters[0].Value = userlevelname;
            parameters[1].Value = piccount;
            parameters[2].Value = basemark;

            return DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
        }
        //
    }
}
